<?php

$inc_core = realpath(dirname(__FILE__) . '/../inc/inc_core.inc');
require_once $inc_core;
use teia\webdev\php\core as teia;

$result = teia\SessionWrapper::start();

if (!$result) {
	echo "<span class=\"error_msg\" id=\"session_error\">\n<p>Session Error: Failed to start session </p>\n</span>\n";
}

$prod = NULL;

if (isset($_REQUEST['Prod_id'])) {
	$prod_id = $_REQUEST['Prod_id'];
	// load product from data cache
	 $prod = teia\DataCache::fetch_product($prod_id);
	// load product from database
	if (!$prod) {
		echo "DEBUG: ProductPage.php: <span class=\"error_msg\">\n<p>Could not load product from data cache using product id: $prod_id </p>\n</span>\n";
		// attempt to load from database		
	}
} elseif (isset($_REQUEST['Item_id'])) {
	$item_id = $_REQUEST['Item_id'];
	// load product from data cache
	$prod = teia\DataCache::fetch_product($prod_id, true);
	if (!$prod) {
		echo "DEBUG: ProductPage.php: <span class=\"error_msg\">\n<p>Could not load product from data cache using item id: $item_id </p>\n</span>\n";
		// attempt to load from database
	}
}

if (!$prod) {
	echo "<span class=\"error_msg\" id=\"prod_error\">\n<p>Fatal Error: Could not load product information! </p>\n</span>\n";
	exit();
}

?>

<!-- Headers -->

<!-- Product Page -->
<div class="product_page">
	<div class="active_item_img">
	</div>
	<div class="left_pane">
		<div class="attrib_pane">
			<div class="prod_attrib">
			</div>
			<div class="item_attrib">
			</div>
		</div>
	</div>
</div>
